package com.fbinggun.fbinggunutil.statistics.command;

import com.fbinggun.fbinggunutil.FBinggunUtil;
import com.fbinggun.fbinggunutil.command.ACommand;
import com.fbinggun.fbinggunutil.command.MainCommand;
import com.fbinggun.fbinggunutil.statistics.StatisticsAPI;
import com.fbinggun.fbinggunutil.statistics.StatisticsInfo;
import org.bukkit.Bukkit;
import org.bukkit.OfflinePlayer;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;

import java.util.List;

public class Create extends ACommand {
    StatisticsAPI api;
    public Create(MainCommand mainCommand) {
        super(mainCommand);
        api= FBinggunUtil.plugin.getStatistMain().getStatApi();
    }

    @Override
    public String getPresentation() {
        return "&e/"+getMainCommand().getCmd()+" "+getId()+" [玩家名] [id] [类型] &7创建统计项";
    }
    @Override
    public boolean isOp() {
        return true;
    }

    @Override
    public String getPermission() {
        return null;
    }

    @Override
    public String getId() {
        return "create";
    }

    //statistics [id] [v] （默认值）
    @Override
    public boolean run(CommandSender sender, String[] args) {
        String defaultV="0";
        if(args.length>=3){
            if(args[2].equals("BOOLEAN")){
                defaultV="true";
            }
            if(args.length==4) {
                defaultV = args[3];
            }
            String id =args[1];
            StatisticsInfo info =api.getDefaultInfo(id);
            if(info!=null){
                getPlugin().sendPlayerMsg(sender, "&c此统计信息已存在 你可以尝试换一个名称创建");
                return false;
            }
            if(api.create(id,args[2],defaultV)){
                getPlugin().sendPlayerMsg(sender, "&a创建成功");
                return false;
            }else {
                getPlugin().sendPlayerMsg(sender, "&a创建失败 类型不存在");
            }


        }






        return false;
    }

    @Override
    public List<String> getTAB(int l, CommandSender sender, String[] args) {
        List<String> list= super.getTAB(l, sender,args);
        if(l==3){
            list.add("DOUBLE");
            list.add("INT");
            list .add("LONG");
            list.add("STRING");
            list.add("BOOLEAN");
        }
        return list;
    }

    @Override
    public boolean isPlayer() {
        return false;
    }

}